<?php

namespace app\models;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use app\models\TaokeOrderInfo;

/**
 * TaokeOrderInfoSearch represents the model behind the search form about `app\models\TaokeOrderInfo`.
 */
class TaokeOrderInfoSearch extends TaokeOrderInfo
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['_id', 'price', 'sales_num', 'use_cnt', 'sort', 'status', 'cid'], 'integer'],
            [['id', 'goodsid', 'title', 'd_title', 'pic', 'org_price', 'istmall', 'dsr', 'sellerid', 'commission', 'commission_jihua', 'commission_queqiao', 'jihua_link', 'que_siteid', 'jihua_shenhe', 'introduce', 'quan_id', 'quan_price', 'quan_time', 'quan_surplus', 'quan_receive', 'quan_condition', 'quan_m_link', 'quan_link', 'ts', 'opty'], 'safe'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = TaokeOrderInfo::find();

        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        // grid filtering conditions
        $query->andFilterWhere([
            '_id' => $this->_id,
            'price' => $this->price,
            'sales_num' => $this->sales_num,
            'ts' => $this->ts,
            'use_cnt' => $this->use_cnt,
            'sort' => $this->sort,
            //'status' => $this->status,
            'status' => 0,
        ]);

        $query->andFilterWhere(['like', 'id', $this->id])
            ->andFilterWhere(['like', 'goodsid', $this->goodsid])
            ->andFilterWhere(['like', 'title', $this->title])
            ->andFilterWhere(['like', 'd_title', $this->d_title])
            ->andFilterWhere(['like', 'pic', $this->pic])
            ->andFilterWhere(['like', 'cid', $this->cid])
            ->andFilterWhere(['like', 'org_price', $this->org_price])
            ->andFilterWhere(['like', 'istmall', $this->istmall])
            ->andFilterWhere(['like', 'dsr', $this->dsr])
            ->andFilterWhere(['like', 'sellerid', $this->sellerid])
            ->andFilterWhere(['like', 'commission', $this->commission])
            ->andFilterWhere(['like', 'commission_jihua', $this->commission_jihua])
            ->andFilterWhere(['like', 'commission_queqiao', $this->commission_queqiao])
            ->andFilterWhere(['like', 'jihua_link', $this->jihua_link])
            ->andFilterWhere(['like', 'que_siteid', $this->que_siteid])
            ->andFilterWhere(['like', 'jihua_shenhe', $this->jihua_shenhe])
            ->andFilterWhere(['like', 'introduce', $this->introduce])
            ->andFilterWhere(['like', 'quan_id', $this->quan_id])
            ->andFilterWhere(['like', 'quan_price', $this->quan_price])
            ->andFilterWhere(['like', 'quan_time', $this->quan_time])
            ->andFilterWhere(['like', 'quan_surplus', $this->quan_surplus])
            ->andFilterWhere(['like', 'quan_receive', $this->quan_receive])
            ->andFilterWhere(['like', 'quan_condition', $this->quan_condition])
            ->andFilterWhere(['like', 'quan_m_link', $this->quan_m_link])
            ->andFilterWhere(['like', 'quan_link', $this->quan_link])
            ->andFilterWhere(['like', 'opty', $this->opty]);

        return $dataProvider;
    }
}
